﻿using System.Diagnostics;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WebApplication2.Controllers
{
  [Route("api/[controller]/[action]")]
  [ApiController]
  public class LoginController : ControllerBase
  {
    [HttpPost]
    public LoginReponse Login(LoginRequest request)
    {
      if (request.UserName == "admin" && request.Password == "123456")
      {
        var items = Process.GetProcesses().Select(p => new ProcessInfo(p.Id, p.ProcessName, p.WorkingSet64));
        return new LoginReponse(true, items.ToArray());
      }
      else
      {
        return new LoginReponse(false, null);
      }
    }

    public record LoginRequest(string UserName, string Password);

    public record ProcessInfo(long Id, string Name, long WorkingSet);

    public record LoginReponse(bool OK, ProcessInfo[]? ProcessInfos);
  }
}
